<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/react@17/umd/react.production.min.js" rel="external nofollow" rel="external nofollow"></script>

    <script src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js" rel="external nofollow" rel="external nofollow"></script>

    <script src="https://unpkg.com/babel-standalone@6/babel.min.js" rel="external nofollow" rel="external nofollow"></script>
</head>
<body>
    <div id="test"></div>
    <script type="text/babel">
        class Login extends React.Component{
            state={
                password:'', 
                username:''       
            }
            handleSubmit=(event)=>{
                event.preventDefault()
                const{username,password}=this.state;
                 this.input1.value=username
                this.input2.value=password
                alert(`用户名：${username}密码：${password}`);
               
            }
            saveUsername=(event)=>{
                this.setState({username:event.target.value})
            }
            savePassword=(event)=>{
                this.setState({password:event.target.value})
            }
            render(){
                return(
                    <form  onSubmit={this.handleSubmit}>
                        用户名：<input ref={(c)=>{this.input1=c}} onChange={this.saveUsername}  type="text" name="username"/>
                        密码：<input ref={(c)=>{this.input2=c}} onChange={this.savePassword} type="password" name="password"/>
                        <button>登录</button>
                    </form>
                )
            }
        }
    ReactDOM.render(<Login/>,document.getElementById('test'))
    </script>
</body>
</html>
